package com.泛型;
/*泛型方法*/
class Generic1{
    public void show(String s){
        System.out.println(s);
    }
    public void show(int i){
        System.out.println(i);
    }
    public void show(boolean b){
        System.out.println(b);
    }
}
//泛型类改进
class Generic2<T>{
    public void show(T t){
        System.out.println(t);
    }
}
//泛型方法改进
class Generic3{
    public <T> void show(T t){
        System.out.println(t);
    }
}

public class GenericDemo2 {
    public static void main(String[] args) {
        Generic1 g1 = new Generic1();
        g1.show("shanxi");
        g1.show(4);
        g1.show(false);
        System.out.println("--------");
        Generic2<String> g2 = new Generic2<String>();
        g2.show("shanxi");
        Generic2<Integer> g3 = new Generic2<Integer>();
        g3.show(4);
        Generic2<Boolean> g4 = new Generic2<Boolean>();
        g4.show(false);
        System.out.println("--------");
        /*使用泛型类每次创建对象时都需要明确数据类型，过于麻烦，泛型方法可以解决这个问题*/
        Generic3 g5 = new Generic3();
        g5.show("shanxi");
        g5.show(4);
        g5.show(false);
    }

}
